
import { commonConstants } from 'hhlt-core/constants'
import { systemUtils} from 'hhlt-core/utils'
import { formatUtils,requestUtils} from 'hhlt-vue/utils'
import { IPageInfo} from 'hhlt-core/src/model/page/pageInfo'
import { IDataTablePager} from 'hhlt-core/src/model/page/dataTablePager'
import { VxeGridPropTypes, VxeTableDefines } from 'vxe-table'
import { IColumnInfo} from 'hhlt-core/src/model/form/column'
import { IExecuteData} from 'hhlt-core/src/model/base/resultModel'
import { FormRules } from 'element-plus'
import { fixedDatasource} from "hhlt-core/constants"
import { objectUtils } from 'hhlt-core/utils'
import { requestContextPath } from 'lxsh-cer-web-pc/src/constants'
import { ICerDeviceImpro, ICerDeviceImproQO, ICerDeviceImproVO,CerDeviceImpro } from 'lxsh-cer-web-pc/src/model/cer/cer/device-impro/cer-device-impro'
/**
* 设备减碳业务实现
*/
export default {
//获取页面信息，根据不同的功能编码来加载不同的页面
getPageInfo:function(pageInfo:IPageInfo<ICerDeviceImpro>){
  this.getColumnInfo()
},
/**
* 获取列信息
*/
getColumnInfo(successCallback?:(columnsParam:VxeGridPropTypes.Columns)=>void){
    var columns:VxeGridPropTypes.Columns = [
      { type: 'checkbox', width: 50 },
      { type: 'seq', width: 60,align:'center',title:'序号' },
      { field: 'id', title: '主键ID', visible:false },
      { field: 'catalog', title: '目录', showOverflow: true, sortable: true,width:'100px' },
      { field: 'profile', title: '简介', showOverflow: true, sortable: true,width:'100px' },
      { field: 'factoryCode', title: '厂区', showOverflow: true, sortable: true,width:'100px' },
      { field: 'startDate', title: '启用时间', formatter: formatUtils.formatDate, showOverflow: true, sortable: true ,width:'160px'},
      { field: 'gasReduceCount', title: '节天然气或节柴油', showOverflow: true, sortable: true,width:'160px' },
      { field: 'electricityReduceCount', title: '节电', showOverflow: true, sortable: true,width:'100px' },
      // { field: 'carbonCount', title: '每日减碳', showOverflow: true, sortable: true,width:'100px' },
      { field: 'carbonCount', title: '减碳量', showOverflow: true, editRender: {}, slots: { edit: 'reduceCount' },sortable: true,width:'120px' },
      { field: 'addDate', title: '添加时间', formatter: formatUtils.formatDateDefault, showOverflow: true, sortable: true ,width:'160px'},
      { title: '操作', width: 200, slots: { default: 'operate' },fixed:'right' }
    ];
    if(successCallback){
      successCallback(columns);
    }
  },
  /**
   * 获取检索条件
   */
  getSearchCondition(successCallback:(searchCondtionParam:IColumnInfo[],queryParams:ICerDeviceImproQO) => void){
    var searchCondition = [
      { columnCode: 'factoryCode', columnName: '厂区', basicControlType:commonConstants.enumBasicControlType.COMBOBOX,defaultValue:"",controlAttrValue:requestContextPath.basedata + '/basedata/factory/getComboList',controlNeedValue:'' },
      // { columnCode: 'startDate', columnName: '启用时间', basicControlType:commonConstants.enumBasicControlType.DATE,defaultValue:"",controlAttrValue:"" },
    ];
    var queryParam:ICerDeviceImproQO = {
        id:undefined,
       /**
	    * factoryCode:厂区
	    */
    factoryCode:"",
       /**
	    * startDate:启用时间
	    */
    startDate:"",
    }
    return successCallback(searchCondition,queryParam);
  },
  /**
   * 单条删除操作
   */
  doDeleteSingle(selectItem:ICerDeviceImproVO,successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/deviceImpro/deleteByLogicBatch';
    let list = new Array();
    let item:ICerDeviceImproQO = {
      id:selectItem.id
    }
    list.push(item)
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 单条删除操作
   */
  doDeleteBatch(selectList:ICerDeviceImproVO[],successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/deviceImpro/deleteByLogicBatch';
    let list = new Array();
    for (let selectItem of selectList) {
      let item :ICerDeviceImproVO = {
        id:selectItem.id
      };
      list.push(item);
    }
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 获取分页数据
   */
  getListByPager(queryParam:ICerDeviceImproQO,pager:IDataTablePager<ICerDeviceImproVO>,successCallback?:(queryResult:IExecuteData<IDataTablePager<ICerDeviceImproVO>>) => void):Promise<IExecuteData<IDataTablePager<ICerDeviceImproVO>>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/deviceImpro/getListByPager';
    return  requestUtils.getListByPager(url, queryParam, pager,successCallback)
  },
  addForm(formData:ICerDeviceImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/deviceImpro/insert";
    return requestUtils.insert(url, formData,successCallback);
  },
  updateForm(formData:ICerDeviceImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/deviceImpro/update";
    return requestUtils.update(url, formData,successCallback);
  },
  updateEnable(formData:ICerDeviceImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/deviceImpro/updateEnable";
    return requestUtils.update(url, formData,successCallback);
  },
  getInfoByCondition(param:ICerDeviceImproQO,successCallback?:(result:IExecuteData<ICerDeviceImproVO>) => void):Promise<IExecuteData<ICerDeviceImproVO>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/deviceImpro/getInfoByCondition";
    return requestUtils.getInfoByCondition(url, param,successCallback);
  },
  //获取表单项
  getFormDataItem(successCallback:(formData:ICerDeviceImpro,verify:FormRules) => void){
    var formData:ICerDeviceImpro = new CerDeviceImpro()
        // 校验
    var verify:FormRules = {
        catalog: [{
            required: true,
            message: "目录不能为空！"
        }],
        profile: [{
            required: true,
            message: "简介不能为空！"
        }],
        factoryCode: [{
            required: true,
            message: "厂区不能为空！"
        }],
        startDate: [{
            required: true,
            message: "启用时间不能为空！"
        }],
        gasReduceCount: [{
            required: true,
            message: "节天然气或节柴油不能为空！"
        }],
        electricityReduceCount: [{
            required: true,
            message: "节电不能为空！"
        }]
    }
    return successCallback(formData,verify)
  }
}
